<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Request;
use ServiceClass\Message;

class MessageController extends Controller
{
    //
    public function __construct(Message $message){

        $this->message = $message;
    }

    public function addMessage(){

        $input = Request::only('message_aid','message_content');

        $result = $this->message->addMessage($input);

        if($result == 1){

            return json_encode(['msg'=>'添加留言成功']);
        }else{

            return json_encode(['msg'=>'添加留言失败']);
        }
    }

    public function deleteMessage(){

        $message_id   = Request::only('message_id');

        $result = $this->message->deleteMessage($message_id);
        if($result == 1){

            return json_encode(['msg'=>'删除成功']);
        }else{

            return json_encode(['msg'=>'服务器错误']);
        }
    }

    public function searchMessage(){

        $message_id   = Request::only('message_id');

        $result = $this->message->searchMessage($message_id);
        if($result == 0){

            return json_encode(['msg'=>'服务器错误']);
        }else{

            return json_encode($result);
        }
    }

    public function selectMessageList(){

        $data = Request::all();
        $page = $data['page'];
        $result = $this->message->selectMessageList('message','1','',$page);



        return json_encode($result);

    }

}
